package com.example.demo.dto;


/**
 * 数据源任务统计信息DTO
 */
public class DataSourceTaskStatsDTO {
    private Long dataSourceId;       // 数据源ID
    private String dataSourceName;   // 数据源名称
    private Long taskTypeId;         // 任务类型ID
    private String taskTypeName;     // 任务类型名称
    private Long totalTasks;         // 总任务数
    private Long assignedTasks;      // 已分配流程任务数
    private Long unassignedTasks;    // 未分配流程任务数
    private Double assignedRate;     // 分配率(百分比)

    public Long getDataSourceId() {
        return dataSourceId;
    }

    public void setDataSourceId(Long dataSourceId) {
        this.dataSourceId = dataSourceId;
    }

    public String getDataSourceName() {
        return dataSourceName;
    }

    public void setDataSourceName(String dataSourceName) {
        this.dataSourceName = dataSourceName;
    }

    public Long getTaskTypeId() {
        return taskTypeId;
    }

    public void setTaskTypeId(Long taskTypeId) {
        this.taskTypeId = taskTypeId;
    }

    public String getTaskTypeName() {
        return taskTypeName;
    }

    public void setTaskTypeName(String taskTypeName) {
        this.taskTypeName = taskTypeName;
    }

    public Long getTotalTasks() {
        return totalTasks;
    }

    public void setTotalTasks(Long totalTasks) {
        this.totalTasks = totalTasks;
    }

    public Long getAssignedTasks() {
        return assignedTasks;
    }

    public void setAssignedTasks(Long assignedTasks) {
        this.assignedTasks = assignedTasks;
    }

    public Long getUnassignedTasks() {
        return unassignedTasks;
    }

    public void setUnassignedTasks(Long unassignedTasks) {
        this.unassignedTasks = unassignedTasks;
    }

    public Double getAssignedRate() {
        return assignedRate;
    }

    public void setAssignedRate(Double assignedRate) {
        this.assignedRate = assignedRate;
    }

    /**
     * 计算分配率
     */
    public void calculateAssignedRate() {
        if (totalTasks != null && totalTasks > 0) {
            this.assignedRate = (assignedTasks != null ? assignedTasks : 0) * 100.0 / totalTasks;
            // 保留两位小数
            this.assignedRate = Math.round(this.assignedRate * 100.0) / 100.0;
        } else {
            this.assignedRate = 0.0;
        }
    }
    
    /**
     * 构造函数
     */
    public DataSourceTaskStatsDTO() {}
    
    public DataSourceTaskStatsDTO(Long dataSourceId, String dataSourceName, 
                                  Long totalTasks, Long assignedTasks, Long unassignedTasks) {
        this.dataSourceId = dataSourceId;
        this.dataSourceName = dataSourceName;
        this.totalTasks = totalTasks;
        this.assignedTasks = assignedTasks;
        this.unassignedTasks = unassignedTasks;
        calculateAssignedRate();
    }
    
    public DataSourceTaskStatsDTO(Long dataSourceId, String dataSourceName, Long taskTypeId, String taskTypeName,
                                  Long totalTasks, Long assignedTasks, Long unassignedTasks) {
        this.dataSourceId = dataSourceId;
        this.dataSourceName = dataSourceName;
        this.taskTypeId = taskTypeId;
        this.taskTypeName = taskTypeName;
        this.totalTasks = totalTasks;
        this.assignedTasks = assignedTasks;
        this.unassignedTasks = unassignedTasks;
        calculateAssignedRate();
    }
}